﻿using Engine;
using Game;


public class ZiYieWidget : CanvasWidget
{
    public ComponentPlayer m_componentPlayer;

    public SubsystemNK m_subsystemHL;

    public ComponentMiner componentMiner;

    public NK9 nk;

    public ButtonWidget m_ZiYieButton;
    public ButtonWidget m_ZiYie1Button;
    public ButtonWidget m_ZiYie2Button;
    public ButtonWidget m_ZiYie3Button;
    public ButtonWidget m_ZiYie4Button;
    public ButtonWidget m_ZiYie5Button;
    public GridPanelWidget m_inventoryGrid;

    public IInventory m_inventory;
    public SubsystemGameInfo m_subsystemGameInfo;
    public SubsystemTime subsystemTime;
    //下面是新人物状态按钮系统
    public ZiYieWidget(ComponentPlayer componentPlayer, SubsystemNK subsystemHL)
    {
        m_componentPlayer = componentPlayer;
        m_inventory = m_componentPlayer.ComponentMiner.Inventory;
        /*XElement node = ContentManager.Get<XElement>("Widgets/任务");
        LoadContents(this, node);
        m_ZiYieButton = Children.Find<ButtonWidget>("ZiYieButton");
        m_ZiYie2Button = Children.Find<ButtonWidget>("ZiYie2Button");
        m_ZiYie1Button = Children.Find<ButtonWidget>("ZiYie1Button");
        m_ZiYie3Button = Children.Find<ButtonWidget>("ZiYie3Button");
        m_ZiYie4Button = Children.Find<ButtonWidget>("ZiYie4Button");
        m_ZiYie5Button = Children.Find<ButtonWidget>("ZiYie5Button");
        m_inventoryGrid = Children.Find<GridPanelWidget>("InventoryGrid");
   */ }
    public override void MeasureOverride(Vector2 parentAvailableSize)
    {
        int max = (m_inventory is ComponentCreativeInventory) ? 10 : 7;
        m_inventory.VisibleSlotsCount = MathUtils.Clamp((int)((parentAvailableSize.X - 320f - 25f) / 72f), 7, max);
        if (m_inventory.VisibleSlotsCount != m_inventoryGrid.Children.Count)
        {
            m_inventoryGrid.Children.Clear();
            m_inventoryGrid.RowsCount = 1;
            m_inventoryGrid.ColumnsCount = m_inventory.VisibleSlotsCount;
            for (int i = 0; i < m_inventoryGrid.ColumnsCount; i++)
            {
                var inventorySlotWidget = new InventorySlotWidget();
                inventorySlotWidget.AssignInventorySlot(m_inventory, i);
                inventorySlotWidget.Size = new Vector2(50f, 50f);
                inventorySlotWidget.BevelColor = new Color(181, 172, 154) * 0.6f;
                inventorySlotWidget.CenterColor = new Color(181, 172, 154) * 0.33f;
                m_inventoryGrid.Children.Add(inventorySlotWidget);
                m_inventoryGrid.SetWidgetCell(inventorySlotWidget, new Point2(i, 0));
            }
        }
        base.MeasureOverride(parentAvailableSize);
    }

    public override void Update()
    {
        int activeBlockValue = m_componentPlayer.ComponentMiner.ActiveBlockValue;
        int num = Terrain.ExtractContents(activeBlockValue);
        if (m_ZiYieButton.IsClicked)
        {
            if (num != 572)
            {
                m_componentPlayer.ComponentGui.DisplayLargeMessage("接收任务1", "寻找2阶灵晶", 5f, 0f);
                m_componentPlayer.ComponentGui.DisplaySmallMessage("需要达到10级", Color.White, blinking: true, playNotificationSound: false);
            }
            if (num == 572)
            {
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务：", "寻找2阶灵晶", 5f, 0f);
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(429, 1, m_componentPlayer.ComponentBody.Position, default, default);
            }
        }
        if (m_ZiYie1Button.IsClicked)
        {
            if (num != 573)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("需要达到20级", Color.White, blinking: true, playNotificationSound: false);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("接收任务2", "寻找3阶灵晶", 5f, 0f);
            }
            if (num == 573)
            {
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务2", "寻找3阶灵晶", 5f, 0f);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(430, 1, m_componentPlayer.ComponentBody.Position, default, default);
            }
        }
        if (m_ZiYie2Button.IsClicked)
        {
            if (num == 574)
            {
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务3", "寻找4阶灵晶", 5f, 0f);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(431, 1, m_componentPlayer.ComponentBody.Position, default, default);
            }
            if (num != 574)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("需要达到30级", Color.White, blinking: true, playNotificationSound: false);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("接收任务3", "寻找4阶灵晶", 5f, 0f);
            }
        }
        if (m_ZiYie3Button.IsClicked)
        {
            if (num == 575)
            {
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(432, 1, m_componentPlayer.ComponentBody.Position, default, default);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务4", "寻找5阶灵晶", 5f, 0f);
            }
            if (num != 575)
            {
                m_componentPlayer.ComponentGui.DisplayLargeMessage("接收任务4", "寻找5阶灵晶", 5f, 0f);
                m_componentPlayer.ComponentGui.DisplaySmallMessage("需要达到40级", Color.White, blinking: true, playNotificationSound: false);
            }
        }
        if (m_ZiYie4Button.IsClicked)
        {
            if (num == 576)
            {
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务5", "寻6阶灵晶", 5f, 0f);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(433, 1, m_componentPlayer.ComponentBody.Position, default, default);
            }
            if (num != 576)
            {
                m_componentPlayer.ComponentGui.DisplayLargeMessage("接收任务5", "寻找6阶灵晶，手持灵晶", 5f, 0f);
                m_componentPlayer.ComponentGui.DisplaySmallMessage("需要达到50级", Color.White, blinking: true, playNotificationSound: false);
            }
        }

        if (m_ZiYie5Button.IsClicked)
        {
            if (num != 572 && num != 573 && num != 574 && num != 575 && num != 576)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("右边选择的物品无效", Color.White, blinking: true, playNotificationSound: false);
            }
            if (num == 572)
            {
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务：", "寻找2阶灵晶", 5f, 0f);
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(429, 1, m_componentPlayer.ComponentBody.Position, default, default);
            }
            if (num == 573)
            {
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务2", "寻找3阶灵晶", 5f, 0f);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(430, 1, m_componentPlayer.ComponentBody.Position, default, default);
            }
            if (num == 574)
            {
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务3", "寻找4阶灵晶", 5f, 0f);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(431, 1, m_componentPlayer.ComponentBody.Position, default, default);
            }
            if (num == 575)
            {
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(432, 1, m_componentPlayer.ComponentBody.Position, default, default);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务4", "寻找5阶灵晶", 5f, 0f);
            }
            if (num == 576)
            {
                m_componentPlayer.ComponentMiner.RemoveActiveTool(1);
                m_componentPlayer.ComponentGui.DisplayLargeMessage("完成任务5", "寻6阶灵晶", 5f, 0f);
                m_componentPlayer.Project.FindSubsystem<SubsystemPickables>(throwOnError: true).AddPickable(433, 1, m_componentPlayer.ComponentBody.Position, default, default);
            }
        }
    }
}
